import 'package:flutter/material.dart';
import '/components/page/common.dart';
import '/utils/setting.dart';
import '/components/actions/search.dart';
import '/components/actions/pop_menu.dart';
import '/components/list/route_menu_item.dart';

class DiscoverPage extends StatelessWidget {
  const DiscoverPage({super.key});

  @override
  Widget build(BuildContext context) {
    return CommonPage(
      title: '发现',
      actions: [const SearchAction(), popupMenuWidget()],
      child: Container(
        color: DefaultColor.primary,
        child: const DiscoverWidget(),
      ),
    );
  }
}

// 发现页
class DiscoverWidget extends StatelessWidget {
  const DiscoverWidget({super.key});

  @override
  Widget build(BuildContext context) {
    List listData = [
      {
        'title': '朋友圈',
        'leftImgPath': 'assets/tabBar/discover/ic_social_circle.png',
        'onTap': () {
          Navigator.pushNamed(context, 'FriendsCirclePage');
        },
      },
      {
        'title': '视频号',
        'leftImgPath': 'assets/tabBar/discover/ic_video_number.png',
        'hasBottom': false,
      },
      {
        'title': '直播',
        'leftImgPath': 'assets/tabBar/discover/ic_live.png',
      },
      {
        'title': '扫一扫',
        'leftImgPath': 'assets/tabBar/discover/ic_quick_scan.png',
        'hasBottom': false,
      },
      {
        'title': '听一听',
        'leftImgPath': 'assets/tabBar/discover/ic_music.png',
      },
      {
        'title': '摇一摇（已下架）',
        'leftImgPath': 'assets/tabBar/discover/ic_shake_phone.png',
      },
      {
        'title': '看一看',
        'leftImgPath': 'assets/tabBar/discover/ic_feeds.png',
        'hasBottom': false,
      },
      {
        'title': '搜一搜',
        'leftImgPath': 'assets/tabBar/discover/ic_quick_search.png',
      },
      {
        'title': '附近的人',
        'leftImgPath': 'assets/tabBar/discover/ic_people_nearby.png',
      },
      {
        'title': '购物',
        'leftImgPath': 'assets/tabBar/discover/ic_shopping.png',
        'hasBottom': false
      },
      {
        'title': '游戏',
        'leftImgPath': 'assets/tabBar/discover/ic_game_entry.png',
        'rightText': '最强王者晋级之路'
      },
      {
        'title': '小程序',
        'leftImgPath': 'assets/tabBar/discover/ic_mini_program.png',
      },
    ];

    // 防止列表过长，超出滚动范围  map前添加可模拟超出：.expand((item) => List.filled(2, item))
    return SingleChildScrollView(
      child: Column(
          children: listData.map((item) => RouteMenuItem(
            leftImgPath: item['leftImgPath'],
            title: item['title'],
            hasBottom: item['hasBottom'] ?? true,
            rightText: item['rightText'],
            onTap: item['onTap'] ?? () {
              Navigator.pushNamed(context, 'EmptyPage', arguments: {
                'title': item['title']
              });
            },
          )).toList()
      ),
    );
  }
}

